﻿open Symbols
open CSModel
open CSSolver

//4 queens constraint satisfaction problem

let domain = intSet [for i in 1..4 -> i] 

//variables
let x1 = VarDef("x1", domain)
let x2 = VarDef("x2", domain)
let x3 = VarDef("x3", domain)
let x4 = VarDef("x4", domain)

let constraints =
    //constaints
    [
        //all different
        &x1 != &x2
        &x2 != &x3
        &x3 != &x4
        &x1 != &x3
        &x2 != &x4
        //safe
        Abs(&x1 - &x2) != 1I
        Abs(&x2 - &x3) != 1I
        Abs(&x3 - &x4) != 1I
        Abs(&x1 - &x3) != 2I
        Abs(&x1 - &x4) != 3I
        Abs(&x2 - &x4) != 2I
    ]

let cs = ConstraintSystem([x1;x2;x3;x4], constraints)

let solSet = solve cs

let ss = solSet|>enumerateSolutions